<!DOCTYPE html>
<html lang="en">
<body>
<div id="msg"></div>
<input type="text" id="text">
<input type="submit" value="send" onclick="send()">
</body>
<script>
    var msg = document.getElementById("msg");

    /*
    //token
    let params='?loginType=1&loginMethod=0&token='+'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb21wYW55Q29kZSI6IkNvbV83NzciLCJsb2dpblVzZXJOYW1lIjoi6IyD6Zuq5p6XIiwibG9naW5Vc2VyQ2xhc3MiOiIyIiwibG9naW5CU2hvcCI6Im51bGwiLCJleHAiOjE1ODkyNTE5ODYsInVzZXJJZCI6ImZ4bCIsImxvZ2luQlN5c3RlbSI6IjAifQ.wlRAOIatzlInD3PVeahVHHX7tMxDojZr1ZWXDmaH7aQ';
    var wsServer = 'ws://127.0.0.1:8999/websocket'+params;
    */

    let params='?loginType=1&loginMethod=2&user='+'luanxd';
    var wsServer = 'ws://127.0.0.1:8999/websocket'+params;

    var websocket = new WebSocket(wsServer);


    //监听连接打开
    websocket.onopen = function (evt) {
        msg.innerHTML = "The connection is open";
    };

    //监听服务器数据推送
    websocket.onmessage = function (evt) {

        msg.innerHTML += evt.data;
    };

    //监听连接关闭
    websocket.onclose = function (evt) {
        alert("connection is closed");
    };

    function send() {
        var text = document.getElementById("text").value
        sendMessage({type:1,msg:text});
    }


    // Send a message WebSocket
    function sendMessage(msg) {
        var json = JSON.stringify(msg);
        websocket.send(json);
    }


</script>
</html>